 #define temp (A0)
 double v;
 
 int c;
 
 void setup(){
 Serial.begin(9600);
 analogReadResolution(12);
 pinMode(temp,INPUT);
 }

void loop() {
 v = analogRead(temp);
 
 c=convert_adc2temperature(v);
  Serial.println(c);
}

  int convert_adc2temperature(int ax)
{
  int a0;
  int a1;
  int temp0;
  int temp1;
 
 
 
  if(ax <= 2526&&ax > 2254){
  a0=2526;
  a1=2254;
  temp0=0;
  temp1=20;
  }
  else if(ax<= 2254&&ax>1841)
  {
  a0=2254;
  a1=1841;
  temp0=20;
  temp1=40;
  }
  else if(ax<=1841&&ax>1389)
  {
  a0=1841;
  a1=1389;
  temp0=40;
  temp1=60;
  }
  else if(ax<=1389&&ax>988)
  {
  a0=1389;
  a1=988;
  temp0=60;
  temp1=80;
  }
  else if(ax<=988&&ax>657)
  {
  a0=988;
  a1=657;
  temp0=80;
  temp1=100;
  }
   int tempx;
   tempx = temp0+(a0-ax)*(temp1-temp0)/(a0-a1);
   return tempx;

   
}


